#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll dp[20][20],b[20];

ll f(ll pos,bool limit,ll pre){
    if(pos<=0)return 1;
    if(!limit&&dp[pos][pre]!=-1)return dp[pos][pre];
    ll up=limit?b[pos]:9;
    ll sum=0;
    for(ll i=0;i<=up;i++){
        if(pre==6&&i==2||i==4)continue;
        else sum+=f(pos-1,limit&&i==b[pos],i);
    }
    if(!limit){
        dp[pos][pre]=sum;
    }
    return sum;
}

ll getsum(ll n){
    //memset(dp,-1,sizeof(dp));
    ll len=0;
    while(n){
        b[++len]=n%10;
        n/=10;
    }
    return f(len,true,0);
}

int main()
{
    IOS;
    ll a,b;
    memset(dp,-1,sizeof(dp));
    while(cin>>a>>b&&(a||b)){
        cout<<getsum(b)-getsum(a-1)<<endl;
    }
    getchar();
    getchar();
    return 0;
}
